package com.ehi.cuke.common.context;

import com.ehi.cuke.AuthorizationHeader;

import javax.ws.rs.core.Response;
import java.util.HashMap;
import java.util.Map;

public class RestClientContext {

	private Response response;

	private String responseJson;

	private Map<String, String> requestHeaders;

	private Map<String, String> cookies;

	private boolean isReaded = false;

	private AuthorizationHeader authorizationHeader;

	public RestClientContext() {
		cookies = new HashMap<>();
		requestHeaders = new HashMap<>();
		authorizationHeader = new AuthorizationHeader();
	}

	public Response getResponse() {
		return response;
	}

	public void setResponse(Response response) {
		this.response = response;
	}

	public String getResponseJson() {
		if (!isReaded) {
			responseJson = response.readEntity(String.class);
			isReaded = true;
		}
		return responseJson;
	}

	public String setRequestHeader(String key, String value) {
		return requestHeaders.put(key, value);
	}

	public String getRequestHeader(String key) {
		return requestHeaders.get(key);
	}

	public Map<String, String> getRequestHeaders() {
		return requestHeaders;
	}

	public void setCookie(String key, String value) {
		cookies.put(key, value);
	}

	public Map<String, String> getCookies() {
		return cookies;
	}

	public AuthorizationHeader getAuthorizationHeader() {
		return authorizationHeader;
	}
}
